﻿using System;
using RpcHelper;
using RpcModularModel.Resource;
using SqlExecHelper;
using SqlExecHelper.Insert;
using Wedonek.RpcStore.Service.Model;
namespace Wedonek.RpcStore.Service.DAL
{
        internal class IdentityProwerDAL : SqlBasicClass
        {
                public IdentityProwerDAL() : base("IdentityPrower", "RpcExtendService")
                {

                }

                public void Clear(Guid appId)
                {
                        base.Drop("AppId", appId);
                }



                public string[] GetProwers(Guid appId, string systemType, ResourceType type)
                {
                        return base.GetOutColumn<string>("Value", new ISqlWhere[] {
                                new SqlWhere("AppId", System.Data.SqlDbType.UniqueIdentifier){Value=appId},
                                new SqlWhere("SystemType", System.Data.SqlDbType.VarChar,50){Value=systemType},
                                new SqlWhere("ResourceType", System.Data.SqlDbType.SmallInt){Value=type}
                        });
                }
                public string[] GetSystemType(Guid appId)
                {
                        return base.GetOutColumn<string>("SystemType", new ISqlWhere[] {
                                new SqlWhere("AppId", System.Data.SqlDbType.UniqueIdentifier){Value=appId},
                                new SqlWhere("ResourceType", System.Data.SqlDbType.SmallInt){Value=ResourceType.RPC节点}
                        });
                }
                public void Adds(IdentityProwerList add)
                {
                        IInsertTable table = base.InsertTable(add.Values.Length, 5);
                        table.Column = new TableColumn[]
                        {
                                new TableColumn("Id", System.Data.SqlDbType.UniqueIdentifier),
                                new TableColumn("AppId", System.Data.SqlDbType.UniqueIdentifier),
                                new TableColumn("SystemType", System.Data.SqlDbType.VarChar,50),
                                new TableColumn("ResourceType", System.Data.SqlDbType.SmallInt),
                                new TableColumn("Value", System.Data.SqlDbType.VarChar,100)
                        };
                        add.Values.ForEach(a =>
                       {
                               table.AddRow(Tools.NewGuid(), add.AppId, a.SystemType, a.ResourceType, a.Value);
                       });
                        table.Save();
                }
        }
}
